home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / utilities / easyproc2.lha / EasyProcess / hc / file.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-05  |  2.0 KB  |  149 lines

  1. /*
  2.  *    File functions.
  3.  */
  4.  
  5. #include "hc.h"
  6.  
  7. UBYTE *FileNames[NUM_FILES] =
  8. {
  9.     "\004" "Root",
  10.     "\001" "1",
  11.     "\001" "2",
  12.     "\001" "3",
  13.     "\001" "4",
  14.     "\001" "5",
  15.     "\001" "6",
  16.     "\004" "Loop",
  17.     "\005" "Modem",
  18.     "\004" "From",
  19.     "\002" "To",
  20.     "\004" "Baud",
  21. };
  22.  
  23. UBYTE *ShowNames[NUM_FILES] =
  24. {
  25.     "\007" "RootHC:",
  26.     "\025" "1     » HC11 numéro 1",
  27.     "\025" "2     » HC11 numéro 2",
  28.     "\025" "3     » HC11 numéro 3",
  29.     "\025" "4     » HC11 numéro 4",
  30.     "\025" "5     » HC11 numéro 5",
  31.     "\025" "6     » HC11 numéro 6",
  32.     "\031" "Loop  » Retour de données",
  33.     "\022" "Modem » Pour modem",
  34.     "\025" "From  » Décodage HC11",
  35.     "\025" "To    » Encodage HC11",
  36.     "\027" "Baud  » Vitesse du port",
  37. };
  38.  
  39. /*
  40.  *    UBYTE *GetName (UWORD File)
  41.  *
  42.  *        Find the name of a file.
  43.  */
  44.  
  45. UBYTE *GetName (UWORD File)
  46. {
  47.     return FileNames[File];
  48. }
  49.  
  50.  
  51. /*
  52.  *    UBYTE *ShowName (UWORD File)
  53.  *
  54.  *        Find the name of a file.
  55.  */
  56.  
  57. UBYTE *ShowName (UWORD File)
  58. {
  59.     return ShowNames[File];
  60. }
  61.  
  62.  
  63. /*
  64.  *    UBYTE *GetComment (UWORD File)
  65.  *
  66.  *        Find the comment of a file.
  67.  */
  68.  
  69. UBYTE *GetComment (UWORD File)
  70. {
  71.     return "";
  72. }
  73.  
  74.  
  75. /*
  76.  *    UWORD WhichFile (UBYTE *Name)
  77.  *
  78.  *        Find the number associated with a name.
  79.  */
  80.  
  81. UWORD WhichFile (UBYTE *Name)
  82. {
  83.     UWORD i, len;
  84.     UBYTE *temp;
  85.  
  86.  
  87.     /*
  88.      *    Get the position (numerical and pointer) of the first character of a
  89.      *    column (:).  If there are no column, set it to the first character.
  90.      */
  91.  
  92.     i = 0;
  93.     len = *Name;
  94.     temp = Name + 1;
  95.  
  96.     while (1)
  97.     {
  98.         if (i == len)
  99.         {
  100.             i = 0;
  101.             temp = Name + 1;
  102.             break;
  103.         }
  104.         if (*temp == ':')
  105.         {
  106.             temp++;
  107.             i++;
  108.             break;
  109.         }
  110.         temp++;
  111.         i++;
  112.     }
  113.  
  114.     /*
  115.      *    Now check if the character position we have is valid, that is to say
  116.      *    that it's not past the end of the string.
  117.      */
  118.  
  119.     if (i >= len)
  120.         return 0;
  121.  
  122.     /*
  123.      *    Now, go past all heading slashes in the name.
  124.      */
  125.  
  126.     while (i < len)
  127.     {
  128.         if (*temp != '/')
  129.             break;
  130.         temp++;
  131.         i++;
  132.     }
  133.  
  134.     if (i >= len)
  135.         return 0;
  136.  
  137.     /*
  138.      *    Now we are at the filename !
  139.      */
  140.  
  141.     len -= i;
  142.  
  143.     for (i = 1; i < NUM_FILES; i++)
  144.         if (!strnicmp (temp, FileNames[i] + 1, (UWORD)FileNames[i][0]))
  145.             return i;
  146.  
  147.     return -1;
  148. }
  149.